from artifacts.base.sr.relics_impl import *
from artifacts.base.attr_type import AttrType


need_main_attr = {
    Head: AttrType.SR_HP,
    Hands: AttrType.SR_ATK,
    Body: AttrType.SR_CRIT_RATE,
    Feet: AttrType.SR_SPD,
    Link: AttrType.SR_ATK_P,
    Sphere: AttrType.SR_QUANTUM_DMG,
}

bonus_attr_score = {
    AttrType.SR_ATK_P: 0.6,
    AttrType.SR_CRIT_RATE: 1,
    AttrType.SR_CRIT_DMG: 1,
    AttrType.SR_ATK: 0.2,
    AttrType.SR_SPD: 0.8,
}


def evaluate(artifacts):
    if artifacts.main_attr is not need_main_attr[type(artifacts)]:
        return 0
    if isinstance(artifacts, Body):
        for item in [AttrType.SR_CRIT_DMG]:
            if item not in [bonus_attr.type for bonus_attr in artifacts.bonus_attr_list]:
                return 0
    else:
        for item in [AttrType.SR_CRIT_RATE, AttrType.SR_CRIT_DMG]:
            if item not in [bonus_attr.type for bonus_attr in artifacts.bonus_attr_list]:
                return 0
    score = 1
    for item in artifacts.bonus_attr_list:
        s = bonus_attr_score.get(item.type)
        if s is not None:
            score += s
    if isinstance(artifacts, Hands) or isinstance(artifacts, Head):
        score -= 1
    return score
